/**
 * @copyright chuzhixin 1204505056@qq.com
 * @description router全局配置，如有必要可分文件抽离
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)

export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/web/login/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/singlePage',
    component: EmptyLayout,
    hidden: true,
    children: [
      {
        path: 'privacyPolicy',
        component: () => import('@/views/singlePage/privacyPolicy'),
        meta: {
          title: '隐私协议',
        },
      },
    ],
  },
]
/*当settings.js里authentication配置的是intelligence时，views引入交给前端配置*/
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    alwaysShow: true,
    redirect: '/index',
    meta: {
      title: '首页',
      // icon: 'home',
      affix: true,
      noKeepAlive: true,
    },
    children: [
      {
        path: '/index',
        name: 'Index',
        // redirect: '/web/reportCase/cases',
        component: () => import('@/views/web/home/main'),
        meta: {
          title: '流程发起',
        },
      },
      {
        path: '/ggyTable',
        name: 'ggyTable',
        // redirect: '/web/reportCase/cases',
        component: () => import('@/views/web/ggyTable/main'),
        meta: {
          title: '报表导航',
          permissions: ['ggyTable'],
        },
      },
      {
        path: '/contributionStat',
        name: 'contributionStat',
        // redirect: '/web/reportCase/cases',
        component: () => import('@/views/web/home/contributionStat'),
        meta: {
          title: '贡献率统计',
          permissions: ['contributionStat'],
        },
      },
    ],
  },
  {
    path: '/developer',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '开发管理',
      permissions: ['appManagePage', 'businessManagePage', 'fieldManagePage', 'appButtonPage'],
    },
    children: [
      {
        path: 'appManagePage',
        component: () =>
          import(
            '@/views/web/system/appManagePage'
          ),
        meta: {
          title: 'app管理',
          permissions: ['appManagePage'],
        },
      },
      {
        path: 'appButtonPage',
        component: () =>
          import(
            '@/views/web/system/appButtonPage'
          ),
        meta: {
          title: 'app按钮',
          permissions: ['appButtonPage'],
        },
      },
      {
        path: 'businessManagePage',
        component: () =>
          import(
            '@/views/web/flowManage/businessManagePage'
          ),
        meta: {
          title: '业务管理',
          permissions: ['businessManagePage'],
        },
      },
      {
        name: 'editBusinessPage',
        path: 'editBusinessPage',
        hidden: true,
        component: () =>
          import(
            '@/views/web/flowManage/editBusinessPage'
          ),
        meta: {
          title: '业务配置',
        },
      },
      {
        path: 'fieldManagePage',
        component: () =>
          import(
            '@/views/web/flowManage/fieldManagePage'
          ),
        meta: {
          title: '组件配置',
          permissions: ['fieldManagePage'],
        },
      }
    ],
  },
  {
    path: '/platformBusiness',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '平台管理',
      permissions: ['employeeManagePage', 'companySearchPage', 'companyManagePage', 'companyCompletePage', 'employeeRegistPage'],
    },
    children: [
      {
        path: 'companySearchPage',
        component: () =>
          import(
            '@/views/web/platform/companySearchPage'
          ),
        meta: {
          title: '公司查询',
          permissions: ['companySearchPage'],
        },
      },
      {
        path: 'companyManagePage',
        component: () =>
          import(
            '@/views/web/platform/companyManagePage'
          ),
        meta: {
          title: '公司管理',
          permissions: ['companyManagePage'],
        },
      },
      {
        path: 'employeeManagePage',
        component: () =>
          import(
            '@/views/web/platform/employeeManagePage'
          ),
        meta: {
          title: '员工管理',
          permissions: ['employeeManagePage'],
        },
      },
      {
        path: 'companyCompletePage',
        component: () =>
          import(
            '@/views/web/platform/companyCompletePage'
          ),
        meta: {
          title: '公司/员工审核',
          permissions: ['companyCompletePage'],
        },
      },
      {
        path: 'employeeRegistPage',
        component: () =>
          import(
            '@/views/web/platform/employeeRegistPage'
          ),
        meta: {
          title: '注册审核',
          permissions: ['employeeRegistPage'],
        },
      },
    ]
  },
  {
    path: '/caseDetail',
    component: Layout,
    alwaysShow: true,
    hidden: true,
    meta: {
      title: '案件信息',
    },
    children: [{
      name: 'caseInfoPage',
      path: 'caseInfoPage',
      component: () => import('@/views/web/case/caseInfoPage'),
      hidden: true,
      meta: {
        title: '案件详情',
      },
    }, {
      name: 'caseLogPage',
      path: 'caseLogPage',
      component: () => import('@/views/web/case/caseLogPage'),
      hidden: true,
      meta: {
        title: '日志管理',
      },
    }, {
      name: 'caseExpensePage',
      path: 'caseExpensePage',
      component: () => import('@/views/web/case/caseExpensePage'),
      hidden: true,
      meta: {
        title: '案件报销',
      },
    }, {
      name: 'caseContributionPage',
      path: 'caseContributionPage',
      component: () => import('@/views/web/case/caseContributionPage'),
      hidden: true,
      meta: {
        title: '贡献管理',
      },
    }, {
      name: 'caseBillApplyPage',
      path: 'caseBillApplyPage',
      component: () => import('@/views/web/case/caseBillApplyPage'),
      hidden: true,
      meta: {
        title: '开票管理',
      },
    }, {
      name: 'caseCostPage',
      path: 'caseCostPage',
      component: () => import('@/views/web/case/caseCostPage'),
      hidden: true,
      meta: {
        title: '成本管理',
      },
    }, {
      name: 'caseIncomePage',
      path: 'caseIncomePage',
      component: () => import('@/views/web/case/caseIncomePage'),
      hidden: true,
      meta: {
        title: '案件应付',
      },
    },
    {
      name: 'caseJobPage',
      path: 'caseJobPage',
      hidden: true,
      component: () =>
        import(
          '@/views/web/case/caseJobPage'
        ),
      meta: {
        title: '案件任务',
      },
    }
    ],
  },
  {
    path: '/personal',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '个人数据',
    },
    children: [
      {
        path: 'myCasePage',
        component: () => import('@/views/web/personal/myCasePage'),
        meta: {
          title: '我的案件',
        },
      },
      {
        name: 'myWebMessagePage',
        path: 'myWebMessagePage',
        component: () => import('@/views/web/personal/myWebMessagePage'),
        meta: {
          title: '我的消息',
        },
      },
      {
        path: 'myInvoicePage',
        component: () => import('@/views/web/personal/myInvoicePage'),
        meta: {
          title: '我的差旅票据',
        },
      },
      {
        path: 'myCompanyPage',
        component: () => import('@/views/web/personal/myCompanyPage'),
        meta: {
          title: '公司/员工查询',
        },
      },
      {
        path: 'myDepartmentPage',
        component: () => import('@/views/web/personal/myDepartmentPage'),
        meta: {
          title: '团队管理',
          permissions: ['myDepartmentPage'],
        },
      },
    ]
  },
  {
    path: '/myHoster',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '主办数据舱',
      permissions: ['hosterUnReturnBillPage', 'hosterReturnBillPage'],
    },
    children: [
      {
        path: 'myUnReturnBillPage',
        component: () => import('@/views/web/myHoster/myUnReturnBillPage'),
        meta: {
          title: '未回款',
          permissions: ['hosterUnReturnBillPage'],
        },
      },
      {
        path: 'myReturnBillPage',
        component: () => import('@/views/web/myHoster/myReturnBillPage'),
        meta: {
          title: '回款',
          permissions: ['hosterReturnBillPage'],
        },
      },
    ]
  },
  {
    path: '/mySaleman',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '业务数据舱',
      permissions: ['salemanHome', 'salemanCase', 'salemanUnReturnBill', 'salemanReturnBill', 'salemanUnBillCase', 'salemanIncome'],
    },
    children: [
      {
        path: 'home',
        component: () => import('@/views/web/mySaleman/home'),
        meta: {
          title: '总览',
          permissions: ['salemanHome'],
        },
      },
      {
        path: 'myCasePage',
        component: () => import('@/views/web/mySaleman/myCasePage'),
        meta: {
          title: '案件',
          permissions: ['salemanCase'],
        },
      },
      {
        path: 'myUnReturnBillPage',
        component: () => import('@/views/web/mySaleman/myUnReturnBillPage'),
        meta: {
          title: '未回款',
          permissions: ['salemanUnReturnBill'],
        },
      },
      {
        path: 'myReturnBillPage',
        component: () => import('@/views/web/mySaleman/myReturnBillPage'),
        meta: {
          title: '回款',
          permissions: ['salemanReturnBill'],
        },
      },
      // {
      //   path: 'myUnBillCasePage',
      //   component: () => import('@/views/web/mySaleman/myUnBillCasePage'),
      //   meta: {
      //     title: '未开票',
      //     permissions: ['salemanUnBillCase'],
      //   },
      // },
      {
        path: 'myIncome',
        component: () => import('@/views/web/mySaleman/myIncomePage'),
        meta: {
          title: '提成',
          permissions: ['salemanIncome'],
        },
      },
    ]
  },
  {
    path: '/companyBusiness',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '公司业务',
      permissions: ['casePage', 'unendCasePage', 'endCasePage', 'invoicePage', 'nodeJobPage', 'companySignInPage'],
    },
    children: [
      {
        path: 'casePage',
        name: 'casePage',
        component: () => import('@/views/web/case/casePage'),
        meta: {
          title: '案件管理',
          permissions: ['casePage'],
        },
      },
      {
        path: 'unendCasePage',
        component: () => import('@/views/web/case/casePage'),
        meta: {
          title: '未结案件',
          permissions: ['unendCasePage'],
          status: 10
        },
      },
      {
        path: 'endCasePage',
        component: () => import('@/views/web/case/casePage'),
        meta: {
          title: '已结案件',
          permissions: ['endCasePage'],
          status: 100
        },
      }, {
        path: 'invoicePage',
        component: () => import('@/views/web/case/invoicePage'),
        meta: {
          title: '差旅票据管理',
          permissions: ['invoicePage'],
        },
      },
      {
        path: 'invoiceTypePage',
        component: () => import('@/views/web/case/invoiceTypePage'),
        meta: {
          title: '差旅性质管理',
          permissions: ['invoiceTypePage'],
        },
      },
      {
        path: 'nodeJobPage',
        component: () =>
          import(
            '@/views/web/case/nodeJobPage'
          ),
        meta: {
          title: '任务管理',
          permissions: ['nodeJobPage'],
        },
      },
      {
        path: 'companySignInPage',
        component: () => import('@/views/web/common/companySignInPage'),
        meta: {
          title: '签到查询',
          permissions: ['companySignInPage'],
        },
      },
      {
        path: 'travelPage',
        name: 'travelPage',
        component: () =>
          import(
            '@/views/web/ggyTable/travelPage'
          ),
        meta: {
          title: '出差补贴',
          permissions: ['travelPage'],
        },
      },
    ],
  },
  {
    path: '/companyFinance',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '公司财务',
      permissions: ['financeHome', 'caseBillPage', 'caseBillReturnPage', 'caseBillUnReturnPage', 'caseBillBadDeftPage', 'caseProfitPage'],
    },
    children: [
      {
        path: 'financeHome',
        component: () => import('@/views/web/finance/financeHome'),
        meta: {
          title: '财务概览',
          permissions: ['financeHome'],
        },
      },
      {
        name: 'caseBillPage',
        path: 'caseBillPage',
        component: () => import('@/views/web/finance/caseBillPage'),
        meta: {
          title: '开票管理',
          permissions: ['caseBillPage'],
        },
      },
      {
        name: 'caseBillReturnPage',
        path: 'caseBillReturnPage',
        component: () => import('@/views/web/finance/caseBillReturnPage'),
        meta: {
          title: '回款管理',
          permissions: ['caseBillReturnPage'],
        },
      },
      {
        name: 'caseBillUnReturnPage',
        path: 'caseBillUnReturnPage',
        component: () => import('@/views/web/finance/caseBillUnReturnPage'),
        meta: {
          title: '未回款管理',
          permissions: ['caseBillUnReturnPage'],
        },
      },
      {
        name: 'caseBillBadDeftPage',
        path: 'caseBillBadDeftPage',
        component: () => import('@/views/web/finance/caseBillBadDeftPage'),
        meta: {
          title: '坏账管理',
          permissions: ['caseBillBadDeftPage'],
        },
      },
      {
        path: 'caseProfitPage',
        component: () => import('@/views/web/finance/caseProfitPage'),
        meta: {
          title: '案件成本',
          permissions: ['caseProfitPage'],
        },
      },
    ],
  },
  {
    path: '/organization',
    component: Layout,
    meta: {
      title: '公司人事',
      permissions: ['companyEmployeeManagePage', 'companyDepartmentManagePage', 'companyRoleManagePage', 'contributionProjectPage', 'newsPage', 'outworkerIncomePage', 'inworkerIncomePage'],
    },
    children: [
      {
        path: 'companyEmployeeManagePage',
        component: () => import('@/views/web/orgnization/employeeManagePage'),
        meta: {
          title: '员工管理',
          permissions: ['companyEmployeeManagePage'],
        },
      },
      {
        path: 'companyDepartmentManagePage',
        component: () => import('@/views/web/orgnization/departmentManagePage'),
        meta: {
          title: '部门管理',
          permissions: ['companyDepartmentManagePage'],
        },
      },
      {
        path: 'companyRoleManagePage',
        component: () => import('@/views/web/orgnization/roleManagePage'),
        meta: {
          title: '角色管理',
          permissions: ['companyRoleManagePage'],
        },
      },
      {
        path: 'contributionProjectPage',
        component: () =>
          import(
            '@/views/web/case/contributionProjectPage'
          ),
        meta: {
          title: '贡献项管理',
          permissions: ['contributionProjectPage'],
        },
      },
      {
        path: 'newsPage',
        component: () => import('@/views/web/common/newsPage'),
        meta: {
          title: '通知管理',
          permissions: ['newsPage'],
        },
      },
      {
        name: 'addNews',
        path: 'addNews',
        component: () => import('@/views/web/common/addNewsPage'),
        hidden: true,
        meta: {
          title: '新增通知',
        },
      },
      {
        name: 'editNews',
        path: 'editNews',
        component: () => import('@/views/web/common/editNewsPage'),
        hidden: true,
        meta: {
          title: '通知编辑',
        },
      },
      {
        name: 'outworkerIncomePage',
        path: 'outworkerIncomePage',
        component: () => import('@/views/web/finance/outworkerIncomePage'),
        meta: {
          title: '外勤提成',
          permissions: ['outworkerIncomePage'],
        },
      },
      {
        name: 'inworkerIncomePage',
        path: 'inworkerIncomePage',
        component: () => import('@/views/web/finance/inworkerIncomePage'),
        meta: {
          title: '内勤提成',
          permissions: ['inworkerIncomePage'],
        },
      },
    ],
  },
  {
    path: '/flowManage',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: 'OA管理',
      permissions: ['flowPage'],
    },
    children: [
      {
        path: 'flowPage',
        component: () =>
          import(
            '@/views/web/flowManage/flowPage'
          ),
        meta: {
          title: '流程管理',
          permissions: ['flowPage'],
        },
      },
      {
        name: 'editFlowPage',
        path: 'editFlowPage',
        component: () =>
          import(
            '@/views/web/flowManage/editFlowPage'
          ),
        hidden: true,
        meta: {
          title: '流程编辑',
        },
      },
    ]
  },
  // {
  //   path: '/ggyTable',
  //   component: Layout,
  //   alwaysShow: true,
  //   meta: {
  //     title: '公估云报表',
  //   },
  //   children: [
  //   ]
  // },
  {
    path: '/formManage',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: 'OA审批',
    },
    children: [
      {
        path: 'formPage',
        component: () =>
          import(
            '@/views/web/formManage/companyFormPage'
          ),
        meta: {
          title: '公司表单',
          permissions: ['formPage'],
        },
      },
      {
        path: 'personalFormPage',
        component: () =>
          import(
            '@/views/web/formManage/personalFormPage'
          ),
        meta: {
          title: '表单查询',
          permissions: ['personalFormPage'],
        },
      },
      {
        name: 'formInfoPage',
        path: 'formInfoPage',
        component: () =>
          import(
            '@/views/web/formManage/formInfoPage'
          ),
        meta: {
          title: '表单详情'
        },
        hidden: true,
      },
      {
        name: 'waitHandleFormPage',
        path: 'waitHandleFormPage',
        component: () =>
          import(
            '@/views/web/formManage/waitHandleFormPage'
          ),
        meta: {
          title: '待审核的',
        },
      }
      , {
        path: 'handledFormPage',
        component: () =>
          import(
            '@/views/web/formManage/handledFormPage'
          ),
        meta: {
          title: '已审核的',
        },
      }, {
        path: 'createdFormPage',
        component: () =>
          import(
            '@/views/web/formManage/createdFormPage'
          ),
        meta: {
          title: '我发起的',
        },
      }, {
        path: 'copiedFormPage',
        component: () =>
          import(
            '@/views/web/formManage/copiedFormPage'
          ),
        meta: {
          title: '抄送我的',
        },
      }, {
        path: 'sharedFormPage',
        component: () =>
          import(
            '@/views/web/formManage/sharedFormPage'
          ),
        meta: {
          title: '分享我的',
        },
      },
    ]
  },
  {
    path: '/formFilter',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '表单筛选',
    },
    children: [
      {
        path: 'formInput',
        component: () =>
          import(
            '@/views/web/formFilter/formInput/formInput'
          ),
        meta: {
          title: '表单汇总',
        },
      },
      {
        path: 'formFilter',
        component: () =>
          import(
            '@/views/web/formFilter/formFilter/'
          ),
        meta: {
          title: '表单',
        },
      },
      {
        path: 'formIndex',
        component: () =>
          import(
            '@/views/web/formFilter/formIndex/formIndex'
          ),
        meta: {
          title: '表单筛选',
        },
      },
      {
        name: 'formDetails',
        path: 'formDetails',
        component: () =>
          import(
            '@/views/web/formFilter/formInput/formDetails/formDetails'
          ),
        meta: {
          title: '表单详情'
        },
        hidden: true,
      },
    ]
  },
  {
    path: '/project',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '入户调查',
      permissions: ['surveyProject', 'userSurvey'],
    },
    children: [
      {
        path: 'surveyProject',
        component: () =>
          import(
            '@/views/web/project/survey/surveyProject'
          ),
        meta: {
          title: '项目管理',
          permissions: ['surveyProject'],
        },
      },
      {
        path: 'userSurvey',
        component: () =>
          import(
            '@/views/web/project/survey/userSurvey'
          ),
        meta: {
          title: '勘查项目',
          permissions: ['userSurvey'],
        },
      },
      {
        path: 'unCommitSurvey',
        component: () =>
          import(
            '@/views/web/project/survey/unCommitSurvey'
          ),
        meta: {
          title: '未通过项目',
          permissions: ['userSurvey'],
        },
      },
      {
        path: 'unAuditSurvey',
        component: () =>
          import(
            '@/views/web/project/survey/unAuditSurvey'
          ),
        meta: {
          title: '待审核项目',
          permissions: ['userSurvey'],
        },
      },
      {
        name: 'survey',
        path: 'survey',
        component: () =>
          import(
            '@/views/web/project/survey/survey'
          ),
        hidden: true,
        meta: {
          title: '入户项目',
        },
      },
      {
        name: 'surveyImages',
        path: 'surveyImages',
        hidden: true,
        component: () =>
          import(
            '@/views/web/project/survey/images'
          ),

        meta: {
          title: '图片中转站',
        },
      },
      {
        name: 'surveyDetail',
        path: 'surveyDetail',
        component: () =>
          import(
            '@/views/web/project/survey/surveyDetail'
          ),
        hidden: true,
        meta: {
          title: '入户详情',
        },
      },
      {
        name: 'userSurveyDetail',
        path: 'userSurveyDetail',
        component: () =>
          import(
            '@/views/web/project/survey/userSurveyDetail'
          ),
        hidden: true,
        meta: {
          title: '勘查详情',
        },
      },
      {
        name: 'surveyModify',
        path: 'surveyModify',
        component: () =>
          import(
            '@/views/web/project/survey/surveyModify'
          ),
        hidden: true,
        meta: {
          title: '入户修改',
        },
      },
      {
        name: 'surveyMap',
        path: 'surveyMap',
        component: () =>
          import(
            '@/views/web/project/survey/surveyMap'
          ),
        hidden: true,
        meta: {
          title: '入户地图',
        },
      },
      {
        name: 'surveyImport',
        path: 'surveyImport',
        component: () =>
          import(
            '@/views/web/project/survey/import'
          ),
        hidden: true,
        meta: {
          title: '入户导入',
        },
      },
    ]
  },
  {
    name: 'surveyPlane',
    path: 'surveyPlane',
    component: () =>
      import(
        '@/views/web/project/survey/surveyPlane'
      ),
    hidden: true,
    meta: {
      title: '绘制平面图'
    }
  },
  {
    path: '/workTask',
    component: Layout,
    alwaysShow: true,
    meta: {
      title: '工作计划',
      permissions: ['workTask'],
    },
    children: [
      {
        name: 'workTaskList',
        path: 'workTaskList',
        component: () =>
          import(
            '@/views/web/workTask/workTaskList'
          ),
        meta: {
          title: '任务列表',
          permissions: ['workTask'],
        }
      }]
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: routerMode === 'history' ? publicPath : '',
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
/* const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
}; */

export function resetRouter() {
  router.matcher = new VueRouter({
    base: routerMode === 'history' ? publicPath : '',
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher
}

export default router
